<?php
namespace Tongcheng\Controller;
use Think\Controller;
class QuanReplyController extends CommonController {
    public function index(){
        if(IS_AJAX){
            $model = M("QuanReply");

            $map['tp_quan_replywid'] = session('wid');
            $res['count'] = $model->where($map)->count();
            $page = $_GET['page']?$_GET['page']:1;
            $limit = $_GET['limit']?$_GET['limit']:10;
            $res['list'] = $model->join('tp_member ON tp_quan_reply.openid = tp_member.openid')->where($map)->field("tp_quan_reply.*, tp_member.nickname, tp_member.headimgurl")->order("last_time desc")->page("{$page},{$limit}")->select();

            $this->ajaxReturn($res);
        }else{
            $this->display();
        }
    }

    public function top(){
        $model = M("QuanReply");
        $map['wid'] = session('wid');
        $map['id'] = $_POST['id'];

        $new['is_top'] = $_POST['status'];
        if($model->where($map)->save($new)){
            $this->success("置顶成功！");
        }else{
            $this->error("网络忙，请稍后再试！".$model->getLastSql());
        }
    }

    public function tui(){
        $model = M("QuanReply");
        $map['wid'] = session('wid');
        $map['id'] = $_POST['id'];

        $new['is_tui'] = $_POST['status'];
        if($model->where($map)->save($new)){
            $this->success("推荐成功！");
        }else{
            $this->error("网络忙，请稍后再试！");
        }
    }

    public function del(){
        $model = M("QuanReply");
        $map['wid'] = session('wid');
        $map['id'] = $_POST['id'];

        if($model->where($map)->delete()){
            $this->success("删除成功！");
        }else{
            $this->error("网络忙，请稍后再试！");
        }
    }
}